package com.looso.sfolder.data;

import com.looso.sfolder.ui.MyApplication;

import android.content.SharedPreferences;


public class UserInfo {
	private String username = null;
	private String sessionid = null;
	
//	private String ipAddress = null;
	private String ipAddress = "";
	private String port = "554";
	private String host = null; 
	
	private SharedPreferences sp = null;
	SharedPreferences.Editor editor = null;
	
	private static UserInfo instance = null;
	public static UserInfo getInstance(){
		if(instance == null){
			instance = new UserInfo();
		}
		return instance;
	}
	private UserInfo(){		
		sp = MyApplication.getInstance().getSharedPreferences("settings", 0);
		editor = sp.edit();
		username = sp.getString("username", "");
		ipAddress = sp.getString("ip", "");		
		port = sp.getString("port", "554");
		
		if(port.equals("")){
			host = "https://"+ipAddress+":554";
		}else{
			host = "https://"+ipAddress+":"+port;
		}
		
	}
	
	
	public String getUsername(){
		return this.username;
	}
	
	public String getSessionId(){
		return this.sessionid;
	}
	
	public String getIp(){
		return this.ipAddress;
	}
	public String getPort(){
		return this.port;
	}
	
	public String getHost(){
		return this.host;
	}
	
	public boolean setUsername(String username){
		this.username = username;
		editor.putString("username", username);
		return editor.commit();		
	}
	
	public boolean setIp(String ip){
		this.ipAddress = ip;
		if(port.equals("")){
			host = "https://"+ipAddress+":554";
		}else{
			host = "https://"+ipAddress+":"+port;
		}
		editor.putString("ip", ip);
		return editor.commit();
	}
	
	public boolean setPort(String port){
		this.port = port;
		if(port.equals("")){
			host = "https://"+ipAddress+":554";
		}else{
			host = "https://"+ipAddress+":"+port;
		}
		editor.putString("port", port);
		return editor.commit();
	}
	
	public void setSessionId(String sessionid){
		this.sessionid = sessionid;
	}
}
